milkweeds<-read.csv("milkweedcounts0709BACI.csv", header=TRUE)
urbanmilkweeds.baci<-milkweeds[milkweeds$subset=="Urban",]
write.csv(urbanmilkweeds.baci, file="urbanmilkweeds.baci.csv")

ruralmilkweeds.baci<-milkweeds[milkweeds$subset=="Rural",]
write.csv(ruralmilkweeds.baci, file="ruralmilkweeds.baci.csv")

urbanmilkweeds.baci<-read.csv(file="urbanmilkweeds.baci.csv",header=TRUE)
ruralmilkweeds.baci<-read.csv(file="ruralmilkweeds.baci.csv",header=TRUE)

library(lme4)
urbanmilkweeds.baci$Year<-urbanmilkweeds.baci$Year-2006
ruralmilkweeds.baci$Year<-ruralmilkweeds.baci$Year-2006
urbanmilkweeds.baci$allAsclepias<-urbanmilkweeds.baci$total-urbanmilkweeds.baci$Indian.hemp
ruralmilkweeds.baci$allAsclepias<-ruralmilkweeds.baci$total-ruralmilkweeds.baci$Indian.hemp

summary(glmer(allAsclepias~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))
summary(glmer(allAsclepias~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))


summary(total<-glmer(total~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))
summary(Indian.hemp<-glmer(Indian.hemp~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))
#positive response to a halt in mowing
summary(dwarf2009<-glmer(dwarf2009~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))
summary(showy<-glmer(showy~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))
summary(swamp<-glmer(swamp~  Year + change +(1|Site/SitePlot), data= urbanmilkweeds.baci, family=poisson))

summary(Indian.hemp<-glmer(Indian.hemp~  Year + change +(1|Site), data= urbanmilkweeds.baci, family=poisson))
#positive response to a halt in mowing
summary(dwarf2009<-glmer(dwarf2009~  Year + change +(1|Site), data= urbanmilkweeds.baci, family=poisson))
summary(showy<-glmer(showy~  Year + change +(1|Site), data= urbanmilkweeds.baci, family=poisson))
#positive response to a halt in mowing
summary(swamp<-glmer(swamp~  Year + change +(1|Site), data= urbanmilkweeds.baci, family=poisson))

summary(total<-glmer(total~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))
summary(Indian.hemp<-glmer(Indian.hemp~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))
summary(dwarf2009<-glmer(dwarf2009~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))
summary(showy<-glmer(showy~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))
summary(swamp<-glmer(swamp~  Year + change +(1|Site/SitePlot), data= ruralmilkweeds.baci, family=poisson))

summary(Indian.hemp<-glmer(Indian.hemp~  Year + change +(1|Site), data= ruralmilkweeds.baci, family=poisson))
summary(dwarf2009<-glmer(dwarf2009~  Year + change +(1|Site), data= ruralmilkweeds.baci, family=poisson))
#positive response to an increase in mowing
summary(showy<-glmer(showy~  Year + change +(1|Site), data= ruralmilkweeds.baci, family=poisson))
#Fixed effects:
#Estimate Std. Error z value Pr(>|z|)
#(Intercept) -1.135e+00  3.079e+00  -0.369    0.712
#Year        -6.896e-01  1.105e+00  -0.624    0.533
#change      -3.096e+01  1.193e+06   0.000    1.000

summary(swamp<-glmer(swamp~  Year + change +(1|Site), data= ruralmilkweeds.baci, family=poisson))

library(glmmADMB)
summary(glmmadmb(Indian.hemp~  Year + change +(1|Site), data= ruralmilkweeds.baci, family="nbinom"))
summary(glmmadmb(dwarf2009~  Year + change +(1|Site), data= ruralmilkweeds.baci, family="nbinom"))
summary(model1<-glmmadmb(showy~  Year + change +(1|Site), data= ruralmilkweeds.baci, family="nbinom"))
summary(glmmadmb(Indian.hemp~  Year + change +(1|Site), data= urbanmilkweeds.baci, family="nbinom"))
summary(glmmadmb(dwarf2009~  Year + change +(1|Site), data= urbanmilkweeds.baci, family="nbinom"))
summary(glmmadmb(showy~  Year + change +(1|Site), data= urbanmilkweeds.baci, family="nbinom"))
#AIC: 141.9 
#Coefficients:
#  Estimate Std. Error z value Pr(>|z|)  
#(Intercept)     6.26       4.24    1.48    0.140  
#Year           -2.45       1.95   -1.26    0.209  
#change          3.72       2.22    1.67    0.095 .

milkweeds2008<-read.csv("milkweedcounts0709average2008.csv", header=TRUE)
library(lme4)
summary(glmer(showy~  TREATMENT +(1|Site), data= milkweeds2008, family=poisson))
#Fixed effects:
#Estimate Std. Error z value Pr(>|z|)  
#(Intercept)                 -1.3040     0.8800  -1.482   0.1384  
#TREATMENThayed               0.6244     1.5394   0.406   0.6850  
#TREATMENTinfrequentunhayed   2.5632     1.3897   1.844   0.0651 .
#TREATMENTunmowed             0.9201     1.0670   0.862   0.3885  
#---
#  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

summary(glmer(Indian.hemp~  TREATMENT +(1|Site), data= milkweeds2008, family=poisson))
#Fixed effects:
#Estimate Std. Error z value Pr(>|z|)
#(Intercept)                 -0.9982     1.1790  -0.847    0.397
#TREATMENThayed              -1.1661     2.4106  -0.484    0.629
#TREATMENTinfrequentunhayed  -0.1004     2.2007  -0.046    0.964
#TREATMENTunmowed             0.9164     1.2414   0.738    0.460

library(glmmADMB)
summary(glmmadmb(showy~  TREATMENT +(1|Site), data= milkweeds2008, family="nbinom"))
#                           Estimate Std. Error z value Pr(>|z|)  
#(Intercept)                  1.0440     0.5597    1.87    0.062 .
#TREATMENThayed               0.0287     1.1718    0.02    0.980  
#TREATMENTinfrequentunhayed   1.5565     1.0120    1.54    0.124  
#TREATMENTunmowed             1.0085     0.7758    1.30    0.194

#                           Estimate Std. Error z value Pr(>|z|)  
#(Intercept)                  1.0443     0.5593    1.87    0.062 .
#TREATMENThayed               0.0286     1.1708    0.02    0.981  
#TREATMENTinfrequentunhayed   1.5567     1.0113    1.54    0.124  
#TREATMENTnative              0.7170     1.2441    0.58    0.564  
#TREATMENTunmowed             1.0825     0.8298    1.30    0.192 

